import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'


/** note: Submenu only appear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/Login.vue'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/authredirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/errorPage/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'dashboard', noCache: true }
      }
    ]
  }
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/business',
    component: Layout,
    alwaysShow: true, // will always show the root menu
    meta: {
      title: '业务管理',
      icon: 'lock'
    },
    children: [
      {
        path: 'monitor',
        component: () => import('@/views/business/monitor'),
        name: 'BusinessMonitor',
        meta: {
          title: '在途监控',
          icon: 'international'
        }
      },
      {
        path: 'order',
        component: () => import('@/views/business/order'),
        name: 'BusinessOrder',
        meta: {
          title: '订单管理',
          icon: 'list'
          // if do not set roles, means: this page does not require permission
        }
      }
    ]
  },

  /** When your routing table is too long, you can split it into small modules**/
  {
    path: '/information',
    component: Layout,
    redirect: 'noredirect',
    name: 'Information',
    meta: {
      title: '信息管理',
      icon: 'example'
    },
    children: [
      {
        path: 'car',
        component: () => import('@/views/information/carmanage'),
        name: 'CarManage',
        meta: { title: '车辆管理', icon: 'list' }
      },
      {
        path: 'carEdit',
        component: () => import('@/views/information/carEditcarEdit'),
        name: 'EditCar',
        meta: { title: '编辑车辆信息', noCache: true },
        hidden: true
      },
      {
        path: 'driver',
        component: () => import('@/views/information/driver'),
        name: 'DriverManage',
        meta: { title: '司机管理', icon: 'list' }
      },
      {
        path: 'driverEdit',
        component: () => import('@/views/information/driverEdit'),
        name: 'EditDriver',
        meta: { title: '编辑司机信息', noCache: true },
        hidden: true
      },
    ]
  },
  {
    path: '/worksheet',
    name: 'WorkSheet',
    component: Layout,
    redirect: 'noredirect',
    meta: {
      title: '工单管理',
      icon: 'language'
    },
    children: [
      {
        path: 'list',
        component: () => import('@/views/information/carmanage'),
        name: 'WorkSheetList',
        meta: { title: '我的工单', icon: 'list' }
      },
      {
        path: 'edit/:id(\\\\d+)',
        component: () => import('@/views/example/edit'),
        name: 'EditArticle',
        meta: { title: 'editArticle', noCache: true },
        hidden: true
      },

      {
        path: 'create',
        component: () => import('@/views/information/driver'),
        name: 'WorkSheetCreate',
        meta: { title: '创建工单', icon: 'edit' }
      }
    ]
  },
  {
    path: '/user',
    name: 'UserManagge',
    component: Layout,
    redirect: 'noredirect',
    meta: {
      title: '账号管理',
      icon: 'peoples'
    },
    children: [
      {
        path: 'userlist',
        component: () => import('@/views/information/carmanage'),
        name: 'UserList',
        meta: { title: '用户列表', icon: 'list' }
      },
      {
        path: 'edit/:id(\\\\d+)',
        component: () => import('@/views/example/edit'),
        name: 'EditArticle',
        meta: { title: 'editArticle', noCache: true },
        hidden: true
      },
      {
        path: 'role',
        component: () => import('@/views/information/driver'),
        name: 'UserRole',
        meta: { title: '用户角色', icon: 'lock' }
      }
    ]
  },
  // {
  //   path: '/error',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   name: 'ErrorPages',
  //   meta: {
  //     title: 'errorPages',
  //     icon: '404'
  //   },
  //   children: [
  //     {
  //       path: '401',
  //       component: () => import('@/views/errorPage/401'),
  //       name: 'Page401',
  //       meta: { title: 'page401', noCache: true }
  //     },
  //     {
  //       path: '404',
  //       component: () => import('@/views/errorPage/404'),
  //       name: 'Page404',
  //       meta: { title: 'page404', noCache: true }
  //     }
  //   ]
  // },

  // {
  //   path: '/error-log',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   children: [
  //     {
  //       path: 'log',
  //       component: () => import('@/views/errorLog/index'),
  //       name: 'ErrorLog',
  //       meta: { title: 'errorLog', icon: 'bug' }
  //     }
  //   ]
  // },
  { path: '*', redirect: '/404', hidden: true }
]
